//package com.ciaojian.client.controller;
//
//import com.ciaojian.client.config.ClientApiConfig;
//import com.ciaojian.client.util.SecretHelper;
//import com.ciaojian.client.util.StringUtil;
//import com.ciaojian.core.mapper.UserAMapper;
//import com.ciaojian.core.mapper.UserMapper;
//import com.ciaojian.core.model.User;
//import com.ciaojian.core.util.Result;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import org.apache.commons.lang3.StringUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * 接口权限处理接口
// * cano
// */
//@Api(value = "AuthController", tags = "接口权限控制", description = "接口权限控制")
//@RestController
//@RequestMapping(value = "/rest/auth")
//public class AuthController {
//    @Autowired
//    private HttpServletResponse response;
//    @Autowired
//    private TokenManager tokenManager;
//    @Autowired
//    private HttpServletRequest request;
//    private Logger logger = LoggerFactory.getLogger(AuthController.class);
//    /**
//     * 接口权限注册
//     */
//    @ApiOperation(value = "接口权限注册")
//    @RequestMapping(value = "/reg", method = RequestMethod.GET)
//    public Result reg(@RequestParam(name = "code", required = true) @ApiParam("授权码") String code) {
//        try {
//            if (StringUtils.isBlank(code)) {
//                logger.error("注意1攻击:" + code + "##user-agent##" + request.getHeader("user-agent"));
//                return Result.error("参数不正确");
//            }
//            String json = SecretHelper.decode(code);
//            if (!json.startsWith("{") || !json.endsWith("}")) {
//                logger.error("注意2攻击:" + code + "##json##" + json + "##user-agent##" + request.getHeader("user-agent"));
//                return Result.error("参数不正确");
//            }
//            Token token = StringUtil.getObjectMapper().readValue(json, Token.class);
//            if(token.getCurrentTimeMillis()<System.currentTimeMillis()-2*60*1000||!StringUtils.isNotBlank(token.getKey())){//两分钟，不能超时
//                logger.error("注意3攻击:" + code + "##json##" + json + "##user-agent##" + request.getHeader("user-agent"));
//                return Result.error("超时");
//            }
////            Optional<StoreAuth> pdd=dao.queryForSingleObject(ManagerApiConfig.STOREPROPLATFORM, StoreAuth.class,"select * from store_auth where appid=? and state=0",new Object[]{token.getAppId()});
////            if(!pdd.isPresent()){
////                logger.error("注意4攻击:" + code + "##json##" + json + "##user-agent##" + request.getHeader("user-agent"));
////                return Result.error("参数不正确");
////            }
////            if(!token.getKey().equals(SecretHelper.encode(pdd.get().getKey()))){
////                logger.error("注意5攻击:" + code + "##json##" + json + "##user-agent##" + request.getHeader("user-agent"));
////                return Result.error("参数不正确");
////            }
//            //创建token
//            String tokenKey = tokenManager.createToken(token);
//            response.setHeader(ClientApiConfig.JWT_TOKEN_HEADER_PARAM,
//                    ClientApiConfig.JWT_TOKEN_HEADER_PREFIX + tokenKey);
//            return Result.ok(tokenKey,"成功");
//        }catch (Exception e){
//            logger.error(e.getMessage(),e);
//        }
//        return Result.error("参数不正确");
//    }
//
//
//    @Resource
//    private UserMapper userMapper;
//    @Resource
//    private UserAMapper userAMapper;
//
//    @ApiOperation(value = "同步用户")
//    @GetMapping(value = "/user")
//    public Result user() {
//        int pigeSide = 0;
//        int side =500;
//
////        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
////        List<User> records = new ArrayList<>();
//        List<User> records = new ArrayList<>();
//        for (int i = 1; i < 4000; i++) {
//
//            records = userMapper.selectListsuserCopy1(pigeSide,side);
//            pigeSide += 500;
//
//            for (User record : records) {
//                try {
////                    UserA userA = new UserA();
////                    userA.copy(record);
////                    userA.setId(record.getId());
////                    userA.setWx(true);
////                    userAMapper.insert(userA);
//                    String substring = record.getTelphone().substring(0, 11);
//                    record.setTelphone(substring);
//                    record.updateById();
//                }catch (Exception e){
//                    System.out.println(e.getMessage());
//                }
//            }
//            records = new ArrayList<>();
//        }
//        return Result.error("1");
//    }
//}
